home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 November / SGI Freeware 1999 November - Disc 1.iso / dist / fw_cvs.idb / usr / freeware / lib / cvs / contrib / log.z / log
Text File  |  1999-04-16  |  4KB  |  177 lines

  1. #! /usr/sbin/perl
  2. # -*-Perl-*-
  3. #
  4. # XXX: FIXME: handle multiple '-f logfile' arguments
  5. #
  6. # XXX -- I HATE Perl!  This *will* be re-written in shell/awk/sed soon!
  7. #
  8.  
  9. # Usage:  log.pl [[-m user] ...] [-s] -f logfile 'dirname file ...'
  10. #
  11. #    -m user        - for each user to receive cvs log reports
  12. #            (multiple -m's permitted)
  13. #    -s        - to prevent "cvs status -v" messages
  14. #    -f logfile    - for the logfile to append to (mandatory,
  15. #            but only one logfile can be specified).
  16.  
  17. # here is what the output looks like:
  18. #
  19. #    From: woods@kuma.domain.top
  20. #    Subject: CVS update: testmodule
  21. #
  22. #    Date: Wednesday November 23, 1994 @ 14:15
  23. #    Author: woods
  24. #
  25. #    Update of /local/src-CVS/testmodule
  26. #    In directory kuma:/home/kuma/woods/work.d/testmodule
  27. #    
  28. #    Modified Files:
  29. #        test3 
  30. #    Added Files:
  31. #        test6 
  32. #    Removed Files:
  33. #        test4 
  34. #    Log Message:
  35. #    - wow, what a test
  36. #
  37. # (and for each file the "cvs status -v" output is appended unless -s is used)
  38. #
  39. #    ==================================================================
  40. #    File: test3               Status: Up-to-date
  41. #    
  42. #       Working revision:    1.41    Wed Nov 23 14:15:59 1994
  43. #       Repository revision:    1.41    /local/src-CVS/cvs/testmodule/test3,v
  44. #       Sticky Options:    -ko
  45. #    
  46. #       Existing Tags:
  47. #        local-v2                     (revision: 1.7)
  48. #        local-v1                     (revision: 1.1.1.2)
  49. #        CVS-1_4A2                    (revision: 1.1.1.2)
  50. #        local-v0                     (revision: 1.2)
  51. #        CVS-1_4A1                    (revision: 1.1.1.1)
  52. #        CVS                          (branch: 1.1.1)
  53.  
  54. $cvsroot = $ENV{'CVSROOT'};
  55.  
  56. # turn off setgid
  57. #
  58. $) = $(;
  59.  
  60. $dostatus = 1;
  61.  
  62. # parse command line arguments
  63. #
  64. while (@ARGV) {
  65.         $arg = shift @ARGV;
  66.  
  67.     if ($arg eq '-m') {
  68.                 $users = "$users " . shift @ARGV;
  69.     } elsif ($arg eq '-f') {
  70.         ($logfile) && die "Too many '-f' args";
  71.         $logfile = shift @ARGV;
  72.     } elsif ($arg eq '-s') {
  73.         $dostatus = 0;
  74.     } else {
  75.         ($donefiles) && die "Too many arguments!\n";
  76.         $donefiles = 1;
  77.         @files = split(/ /, $arg);
  78.     }
  79. }
  80.  
  81. # the first argument is the module location relative to $CVSROOT
  82. #
  83. $modulepath = shift @files;
  84.  
  85. $mailcmd = "| Mail -s 'CVS update: $modulepath'";
  86.  
  87. # Initialise some date and time arrays
  88. #
  89. @mos = (January,February,March,April,May,June,July,August,September,
  90.         October,November,December);
  91. @days = (Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday);
  92.  
  93. ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime;
  94.  
  95. # get a login name for the guy doing the commit....
  96. #
  97. $login = getlogin || (getpwuid($<))[0] || "nobody";
  98.  
  99. # open log file for appending
  100. #
  101. open(OUT, ">>" . $logfile) || die "Could not open(" . $logfile . "): $!\n";
  102.  
  103. # send mail, if there's anyone to send to!
  104. #
  105. if ($users) {
  106.     $mailcmd = "$mailcmd $users";
  107.     open(MAIL, $mailcmd) || die "Could not Exec($mailcmd): $!\n";
  108. }
  109.  
  110. # print out the log Header
  111. print OUT "\n";
  112. print OUT "****************************************\n";
  113. print OUT "Date:\t$days[$wday] $mos[$mon] $mday, 19$year @ $hour:" . sprintf("%02d", $min) . "\n";
  114. print OUT "Author:\t$login\n\n";
  115.  
  116. if (MAIL) {
  117.     print MAIL "\n";
  118.     print MAIL "Date:\t$days[$wday] $mos[$mon] $mday, 19$year @ $hour:" . sprintf("%02d", $min) . "\n";
  119.     print MAIL "Author:\t$login\n\n";
  120. }
  121.  
  122. # print the stuff from logmsg that comes in on stdin to the logfile
  123. #
  124. open(IN, "-");
  125. while (<IN>) {
  126.     print OUT $_;
  127.     if (MAIL) {
  128.         print MAIL $_;
  129.     }
  130. }
  131. close(IN);
  132.  
  133. print OUT "\n";
  134.  
  135. # after log information, do an 'cvs -Qq status -v' on each file in the arguments.
  136. #
  137. if ($dostatus != 0) {
  138.     while (@files) {
  139.         $file = shift @files;
  140.         if ($file eq "-") {
  141.             print OUT "[input file was '-']\n";
  142.             if (MAIL) {
  143.                 print MAIL "[input file was '-']\n";
  144.             }
  145.             last;
  146.         }
  147.         $pid = open(RCS, "-|");
  148.         if ( !defined $pid )
  149.         {
  150.             die "fork failed: $!";
  151.         }
  152.         if ($pid == 0)
  153.         {
  154.             exec 'cvs', '-nQq', 'status', '-v', $file;
  155.             die "cvs exec failed: $!";
  156.         }
  157.         while (<RCS>) {
  158.             print OUT;
  159.             if (MAIL) {
  160.                 print MAIL;
  161.             }
  162.         }
  163.         close(RCS);
  164.     }
  165. }
  166.  
  167. close(OUT);
  168. die "Write to $logfile failed" if $?;
  169.  
  170. close(MAIL);
  171. die "Pipe to $mailcmd failed" if $?;
  172.  
  173. ## must exit cleanly
  174. ##
  175. exit 0;
  176.